home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: Dominic Feeley <dom@dfdesign.demon.co.uk>
- Newsgroups: comp.std.c,comp.lang.c.moderated
- Subject: Re: Integral promotion.
- Date: 14 Feb 1996 21:25:15 -0600
- Organization: DF Designs
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4fu92r$9so@solutions.solon.com>
- References: <4fstj7$2l6@solutions.solon.com>
- Reply-To: dom@dfdesign.demon.co.uk
- NNTP-Posting-Host: solutions.solon.com
- X-NNTP-Posting-Host: dfdesign.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.30
- X-Mail2News-Path: dfdesign.demon.co.uk
-
- In article <4fstj7$2l6@solutions.solon.com>
- rune.huseby@gpi.telemax.no "Rune Huseby" writes:
-
- > I got a problem understanding the rules on integral promotion in
- > the C language:
- >
- > short test(short x1, short x2);
- >
- > My compiler (Microsoft Visual C++ 4.0), automagically converts
- > my short-parameters to int's, even though all variables involved
- > are short. I know that the standard says that all arguments can
- > be converted to the biggest 'type' of all the arguments, but is
- > it correct that char's and short's always are promoted to int's,
- > without regard to the other arguments in the expression?
-
- This is news to me, but it seems that section 6.2.1.5 of the standard
- says that the lowest integer type is an int. If I am going to buy these
- things I suppose I ought to read them.
-
- My reading is that
- short result = x1 + x2; /* going from int to short, possible loss of data */
-
- gives the "same" result mathematically as
- short result = ( int ) x1 + ( int ) x2 ;
- i.e. you assign an int to a short value. The results of this conversion
- are ( I think ) implementation-defined if the short is signed.
-
- Regards,
- Dominic.
-
- --
- Dominic Feeley
-